﻿//  --------------------------------
//  Copyright (c) 2010 Michael Schuler, Sascha Burger. All rights reserved.
//  This source code is made available under the terms of the Microsoft Public License (Ms-PL)
//  http://p2pmessaging.codeplex.com/license
//  ---------------------------------
using p2pMessaging.Interfaces;
using p2pMessaging.Interfaces.Contact;

namespace p2pMessaging.BL
{
	/// <summary>
	/// Service to store and delete contacts to a persistency layer.
	/// </summary>
	public sealed class ContactService : IContactService
	{
		private readonly IPersistenceService myPersistenceService;
		
		public ContactService(IPersistenceService persistenceService)
		{
			myPersistenceService = persistenceService;
		}

		/// <summary>
		/// Save an instance of <see cref="IContact"/> to the persistency layer.
		/// </summary>
		/// <param name="contact">Contact to save.</param>
		public void Store(IContact contact)
		{
			myPersistenceService.Store(contact);
		}

		/// <summary>
		/// Remove an instance of <see cref="IContact"/> from the persistency layer.
		/// </summary>
		/// <param name="contact">Contact to delete.</param>
		public void Delete(IContact contact)
		{
			myPersistenceService.Delete(contact);
		}
		
		/// <summary>
		/// Returns a specific contact from the persistency layer by its id.
		/// </summary>
		/// <param name="id">Id to identify a contact.</param>
		/// <returns>The contact if found otherwise null.</returns>
		public IContact Get(string id)
		{
			return myPersistenceService.Get<IContact>(id);
		}
	}
}
